<?php
    require_once "config.php";
    $offer_prefix = trim($_GET['offer_prefix']);    
    if($offer_prefix == '') {
        header("Location:index.php");
        exit;
    }
    $rotator_ids=array();
    $enc_member_id = trim($_GET['k']);    //'key' -> encryption key
    /*if (strlen($enc_member_id)>0){
        $member_obj = new Member();
        $member_obj->set_member_refferal($enc_member_id);
    }*/
    //$reffered_email = trim($_GET['rm']);    //'key' -> encryption key
    if (strlen($enc_member_id)>0 ){  /*checks whether a referred user has visited the site*/    //&& strlen($reffered_email)>0 && validEmail($reffered_email)    //strlen($reffered_email)>0 && validEmail($reffered_email)
        $member_obj = new Member();
        $referrer_details=$member_obj->get_referrer_details($enc_member_id, $reffered_email);
        if(!empty($referrer_details)){
            $_SESSION['referrer_member_id']=$referrer_details['member_id'];
        }        
    }
    
    $offer_obj = new Offer();
    $offer_details = $offer_obj->get_offer_details_by_prefix($offer_prefix);
    if($offer_details['offer_status'] == 'A' ) {
               $you_saved = number_format(floor($offer_details['regular_amount'] - $offer_details['discount_amount']));
               $discount_percentage = ceil((($offer_details['regular_amount'] - $offer_details['discount_amount'])/$offer_details['regular_amount'])*100);
               $item_sold = $offer_obj->get_noof_sold_items($offer_details['offer_id']);
               $price_class = "";
               switch (strlen(floor($offer_details['discount_amount']))) {
                case "3":
                   $price_class ="class='digits3'";
                    break;
                 case "4":
                   $price_class ="class='digits4'";
                    break;
                case "5":
                   $price_class ="class='digits5'";
                    break;
                 case "6":
                   $price_class ="class='digits6'";
                    break;
                 case "7":
                   $price_class ="class='digits7'";
                    break;
               

	
    }
    }
    
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hotels With Offers</title>

<script language="Javascript" type="text/javascript" src="js/jquery.min.js"></script>

<script language="Javascript" type="text/javascript" src="js/jquery.countdown.js"></script>
<script language="Javascript" type="text/javascript" src="js/popup.js"></script>
<link href="css/jquery.countdown.css" rel="stylesheet" type="text/css" />
<link href="css/general.css" rel="stylesheet" type="text/css" />
<link href="css/main.css" rel="stylesheet" type="text/css" />
<?php require_once 'rotator_utils.php'; ?>
<script language="javascript" type="text/javascript">
         $(function(){
          <?php
               $offer_hour = substr($offer_details['offer_end_date'], 11, 2) ;
               $offer_min =  substr($offer_details['offer_end_date'], 14, 2);
               $offer_sec =  substr($offer_details['offer_end_date'], 17, 2);
               $offer_day =  substr($offer_details['offer_end_date'], 8, 2);
               $offer_month = substr($offer_details['offer_end_date'], 5, 2);
               $offer_year =  substr($offer_details['offer_end_date'], 0, 4);
               ?>
        var austDay = new Date(<?=$offer_year?>,<?=($offer_month-1)?>,<?=$offer_day?>,<?=$offer_hour?>,<?=$offer_min?>,<?=$offer_sec?>);
	$('#countdown').countdown({until: austDay});

<?php


        ?>

      });



		</script>
</head>

<body>
<div id="wrapper">
    <?php require_once 'top_header.php'; ?>
    
<div class="contentPane">
  <div id="sidebar">
    <span class="menu"><img src="images/call.png" alt="Advertise with Hotel with Offers" class="callus"  /></span>
    <div class="joinus">
      <h1>INVITE A FRIEND</h1>
      <h2>Tell a friend and win Rs100.00</h2>
      <div class="joinbtn"><a href="#">LEARN&nbsp;MORE</a></div>
     </div>
    <div class="reserve"><span class="reserveitem">Reserved for :</span> <span class="reserveitem">advertising</span> <span class="reserveitem">latest news</span> <span class="reserveitem">soon ending deals &amp; offers</span></div>
  </div>
  <div class="leftPane">
      <div class="mainMenu"><?php require_once 'main_menu.php'; ?></div>
     <?php require_once 'newsletter_plug.php'; ?>
    <div id="Listings">
      <div class="listingdetails">
          <?php if($offer_details == FALSE) {
                    echo "<span>Invalid Offer</span>";
          } else if($offer_details['offer_status'] == 'SO' || $offer_details['offer_status'] == 'C') {
                    echo "<span>This Offer already SOLD OUT or currently cancelled by Admin keep In touch this may be get activated </span>";
          } else if($offer_details['offer_status'] == 'P') {
              echo "<span>This in progress of preparing will be activated soon</span>";
          } else {
          ?>
      <div class="listinggallery">
        <!--<div class="mainimg">  -->
            <div id="rotator<?php echo $offer_details['offer_id']?>" rel="rot">
                <ul>
                    <?php 
                    $rotator_ids[$offer_details['offer_id']]='rotator'.$offer_details['offer_id'];    //used to store the offer ids, to pass to the 'theRotator' funtion
                    $offer_images=$offer_obj->get_offer_images($offer_details['offer_id']);  //loads all the offer images related to the current offer from the offer_order table.
                    if(!empty($offer_images)){
                      foreach ($offer_images as $key => $value): 
                       $class_text='';                      
                       if($key==0){ //starts the rotation from the first image
                           $class_text=' class="show"';
                       }                       
                       $path="images/".$value['image_name'];
                       if(!file_exists("images/".$value['image_name'])){
                           $path="images/mainimg.png";
                       }
                      ?>                    
                        <li <?php echo $class_text;?>><img src="<?php echo $path;?>" width="284" height="199" alt="Hotel with Offers - <?php echo $offer_details['offer_title']?>" /></li>
                      <?php endforeach;?>
                    <li><img src="images/image-4.jpg" width="284" height="199" alt="Hotel with Offers" /></li>
                    <?php }else {?>
                        <li class="show"><img src="images/mainimg.png" width="284" height="199" alt="Hotel with Offers - <?php echo $offer_details['offer_title']?>" /></li>                    
                    <?php }?>
                </ul>            
            </div>
        <!--<img src="images/<?php echo $offer_details['listingpage_image_url'];?>" alt="" style="padding-right:6px;" />-->
        <!--</div>-->
        <!--<img src="images/thumbs/<?php echo $offer_details['listingpage_thumb_image_url'];?>" alt="" style="padding-right:6px;" /><img src="images/thumbs/<?php echo $offer_details['listingpage_thumb_image_url'];?>" alt="" style="padding-right:6px;"/><img src="images/thumbs/<?php echo $offer_details['listingpage_thumb_image_url'];?>" alt="" style="padding-right:6px;"/><img src="images/thumbs/<?php echo $offer_details['listingpage_thumb_image_url'];?>" alt="" />-->
        <div class="socialNetworkWidgetsInner">
            <script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><style> html .fb_share_link { padding:2px 0 0 20px; height:16px; background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top left; }</style><a rel="nofollow" href="http://www.facebook.com/share.php?u=http://www.hotelswithoffers.com/<?php echo $offer_details['offer_prefix']?>.html" onclick="return fbs_click()" target="_blank" class="fb_share_link"></a>
               <a href="https://twitter.com/share?url=http://www.hotelswithoffers.com/<?php echo $offer_details['offer_prefix']?>.html" class="twitter-share-button" data-lang="en">Tweet</a>
               <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
            <a href="#" class="emailaFriend" id="emailaFriend">Email a Friend</a></div>
      </div>
      <div class="listingIntro">
       <div class="buytab"><a href="buynow.php?offer_prefix=<?=$offer_details['offer_prefix']?>" style="text-decoration:none;">BUY NOW</a></div>
       <h1 class="mainheading"><?php echo $offer_details['offer_title']; ?></h1>
       <a href="#" style="text-decoration:none;"></a>
<div class="price currencyUSD">
                <h1><?php echo $discount_percentage;?>% OFF</h1>
                <h2><strong>Rs.</strong><span <?php echo $price_class; ?>"><?php echo number_format(floor($offer_details['discount_amount']));?></span></h2>
                <h3><?php echo $item_sold;?> SOLD</h3>
              </div>
        <p><?php echo $offer_details['offer_in_detail']; ?></p>
			<div class="socialNetworkWidgets">
            
			</div>
             <div class="normalprice">Normal Price<br class="clear" /><span class="normal">Rs.<?php echo number_format(floor($offer_details['regular_amount'])); ?></span></div>
             <div class="specialprice">You Save<br class="clear" /><span class="save">Rs.<?php echo $you_saved; ?></span></div>
             <br class="clear" />
             <div class="countdownInner">
               <div class="countdown">
                 <div id="countdown">
                  
                   </div>
                 </div>
               </div>
            </div>
             <br class="clear" />
             <img src="images/timersep.png" />
             <br class="clear" />
             <div class="terms"><h1>Deal terms & conditions</h1>
             <?php echo $offer_details['terms_and_conditions']; ?>
             </div>
             <br class="clear" />
             <br class="clear" />
             <div class="conditions"><h1>Website terms & conditions</h1>
             <?php echo $offer_details['terms_and_conditions']; ?>
             </div>
      </div>
          <?php } ?>
      </div>

    </div>
    <br class="clear">
</div>
</div>
<br class="clear" />
</div>
<div id="popupContact">
    <a id="popupContactClose">x</a>
    
    <!-- Toggle and show this on success -->
    <div style="display:none" id="popupContact-success">
        <div class="inner">
        <h2>Thank you</h2>
        <h4>Your email has been sent successfully.</h4>
        </div>        
    </div>
    <div style="display:none" id="popupContact-error"></div>
    <div id="invite_friend">
    <h1>Email a Friend</h1>
    <p>Share this great offer with your friend & family, just enter their email and send.</p>
    <form action="" method="post" name="invite_friend_form" id="invite_friend_form">
    <?php if (!isset($_SESSION['member_email'])): ?>    
        <div class="from_email"><input name="from_email" class="tellaFriendField" type="text" value="Your email address" onfocus="if (this.value == 'Your email address') { this.value = ''; }" onblur="if (this.value == '') { this.value = 'Your email address'; }" /></div>        
    <?php else:?>
        <div class="from_email"><input disabled name="Your email address" class="tellaFriendField" type="text" value="<?php echo $_SESSION['member_email'];?>" onfocus="if (this.value == 'Your email address') { this.value = ''; }" onblur="if (this.value == '') { this.value = 'Your email address'; }" /></div>
    <?php endif; ?>
    <div class="to_email"><input name="to_email" class="tellaFriendField" type="text" value="Friend&acute;s email address" onfocus="if (this.value == 'Friend&acute;s email address') { this.value = ''; }" onblur="if (this.value == '') { this.value = 'Friend&acute;s email address'; }" /></div>        
    <? echo '<input name="offer_link" type="hidden" value='. curPageURL(). ' />' ?>
    <div class="invite"><input class="tellaFriendFieldButton" name="submit" id="submit" type="button" value="Send" /></div>  
    </form>    
    </div>   
    <div id="Loader" style="display:none"><img src="images/loading.gif" /></div>
</div>
<div id="backgroundPopup"></div>

<div id="footerWrapper">
<?php require_once 'footer.php'; ?>
</div>
</body>
</html>
<script type="text/javascript">
    $(document).ready(function() {		
	//Load the slideshow
        <?php foreach ($rotator_ids as $val) {?>
            theRotator('<?php echo $val?>');
        <?php }?>
	
	/*$('div.rotator').fadeIn(1000);
        $('div.rotator ul li').fadeIn(1000); // tweek for IE*/
    });
</script>